package org.jha.video.hhnet;

import org.jha.base.BaseStructure;
import org.jha.base.CommonTools;

import com.sun.jna.NativeLong;
import com.sun.jna.Pointer;
import com.sun.jna.platform.win32.WinDef.HWND;
import com.sun.jna.ptr.IntByReference;
import com.sun.jna.win32.StdCallLibrary;

public interface HHNet extends StdCallLibrary {

	public HHNet INSTANCE = CommonTools.loadLibrary(CommonTools.getLibPath()
			+ "\\hhnet\\HHNetClient", HHNet.class);

	int HHNET_Startup(HWND hNotifyWnd, int nCommandID);

	int HHNET_LogonServer(String pServerIP, NativeLong wServerPort,
			String pDeviceName, String pUserName, String pUserPassword,
			int dwClientID, IntByReference hLogonServer);

	int HHNET_LogoffServer(Pointer hServer);

	// int HHNET_ReadServerInfo(IntByReference hServer, HH_SERVER_INFO
	// serverInfo);

	int HHNET_OpenChannel(String pServerIP, NativeLong wServerPort,
			String pDeviceName, String pUserName, String pUserPassword,
			HHOPEN_CHANNEL_INFO_EX pOpenInfo, IntByReference hOpenChannel);

	int HHNET_CloseChannel(int hOpenChannel);

	int HHNET_OpenPicture(String pServerIP, NativeLong wServerPort,
			String pDeviceName, String pUserName, String pUserPassword,
			HHOPEN_PICTURE_INFO pOpenInfo, IntByReference hOpenPicture);

	int HHNET_CapturePicture(int hOpenPicture);

	int HHNET_ClosePicture(int hOpenPicture);

	public static final int USER_NAME_LEN = 16;
	public static final int USER_PASSWD_LEN = 16;
	public static final int MAX_VIDEO_NUM = 4;

	public static interface ChannelStreamCallback extends StdCallCallback {

		void invoke(int hOpenChannel, Pointer pStreamData,
				long dwClientID, HWND pContext,
				ENCODE_VIDEO_TYPE encodeVideoType, Pointer pAVInfo);
	}

	public static interface PictureCallback extends StdCallCallback {

		void invoke(int hPictureChn, Pointer pPicData, int nPicLen,
				long dwClientID, HWND pContext);
	}

	public static class ENCODE_VIDEO_TYPE extends BaseStructure {
		public int type;
	}

	public static class HHOPEN_PICTURE_INFO extends BaseStructure {

		public long dwClientID;
		public long nOpenChannel;
		public int protocolType;
		public PictureCallback funcPictureCallback;
		public HWND pCallbackContext;
	}

	public static class HHOPEN_CHANNEL_INFO extends BaseStructure {

		public int dwClientID;
		public int nOpenChannel;
		public int protocolType;
		public ChannelStreamCallback funcStreamCallback;
		public HWND pCallbackContext;
	}

	public static class HHOPEN_CHANNEL_INFO_EX extends BaseStructure {

		public int dwClientID;
		public int nOpenChannel;
		public int protocolType;
		public ChannelStreamCallback funcStreamCallback;
		public HWND pCallbackContext;
		public int nSubChannel = 0;
		int res = 100;
	}

	public static class HH_SERVER_INFO extends BaseStructure {

		public Pointer hServer;
		public byte[] szServerIP = new byte[129];
		public int nServerPort;
		public byte[] szDeviceName = new byte[33];
		public int nDeviceID;

		public byte[] szUserName = new byte[USER_NAME_LEN + 1];
		public byte[] szUserPassword = new byte[USER_PASSWD_LEN + 1];

		public long dwClientID;

		public int logonStatus;
		public int nVersion;
		public int nLogonID;
		public int nPriority;
		public int nServerChannelNum;
		public int nLanguageNo;
		public int nMachineType;
		public boolean bPalStandard;
		public int nMulticastAddr;
		public int nMulticastPort;
		// public HHAV_INFO avInformation[MAX_VIDEO_NUM];
	}
}
